#ifndef CMATH_H_
#define CMATH_H_

#include <typeinfo>
#include <limits>
#include <float.h>
#include "cfraction.h"
#include "cbigint.h"
#include "../exception/cnumberparseexception.h"

/**
 * CMath - class encapsulates basic mathematic operations and type conversions
 * @author Michal Rost
 * @date 25.05.2007
 */
template<typename T> class CMath : public CObject {
public:
  static T sgn(T num);
  static T degToRad(T angle);
  static T radToDeg(T angle);
  static T min(T n1, T n2);
  static T max(T n1, T n2);
  static T abs(T num);
  static T sqrt(T num);
  static T log2(T num);
  static T pow(T base, double exp);
  static bool equals(T n1, T n2);
  static bool equals(T n1, T n2, T epsilon);
  static int compare(T n1, T n2);
  static int compare(T n1, T n2, T epsilon);
  static int toInt(T num);
  static long toLong(T num);
  static short toShort(T num);
  static float toFloat(T num);
  static double toDouble(T num);
  static CBigInt toBigInt(T num);
  static CFraction toFraction(T num);
  static string toString(T num);
  static T parse(string str) throw(CNumberParseException);
  static long parseHex(string str) throw(CNumberParseException);
  static const double PI = 3.141592653589793;
  static const int MAX_DECIMAL_DIGITS_DOUBLE = 15;
  static const int COMPARE_LESSER = -1;
  static const int COMPARE_EQUAL = 0;
  static const int COMPARE_GREATER = 1;
  static const double EPSILON = 1e-6;
  static string getClassName() {
    static const string CLASS_NAME = "CMath";
    return CLASS_NAME;
  }
private:
  static CFraction doubleToFraction(double value, unsigned char precision);
};

#endif
